<?php
include_once("../modules/checkA.php");
include_once("../../config.php");

$act = isset($_REQUEST['act']) ? $_REQUEST['act'] : '';

$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : '0';


/* 权限判断 */
admin_priv('weixin');

if($act == ''){
	$url = 'detail-list.php';
	header('Location:'.$url);
	exit; 
}

if($id == ''){
	$url = 'detail-list.php';
	header('Location:'.$url);
	exit; 
}


if($act == 'add' || $act == 'edit'){
			
	$next_act = $act == 'add' ? 'insert' : 'update';
}

if($act == 'edit'){
	
	$detail = select_one_line_all_items($table_Prefix.'wechat_official', "nid = '$id' ");

}
elseif($act == 'update'){
	
	$table    = $table_Prefix ."wechat_official";

	$detail_list = $_REQUEST;

	$sql=update_date($table,$detail_list,"nid",$_REQUEST['ai_nid']);
	
	$res = do_query($sql);

	if($res){
		echo '<script type="text/javascript">alert("修改成功");window.location.href="detail-list.php?nav-itemed=wechat";</script>';
	}
	exit;
		
}
elseif($act == 'insert'){
	
	$insert_array = array();
	$detail_list[0]['name'] = trim($_REQUEST['ai_name']) ;
	$detail_list[0]['appid'] = trim($_REQUEST['ai_appid']) ;
	$detail_list[0]['appsecret'] = trim($_REQUEST['ai_appsecret']) ;
	$detail_list[0]['public_id'] = trim($_REQUEST['ai_public_id']) ;
	$detail_list[0]['account'] = trim($_REQUEST['ai_account']) ;
	$detail_list[0]['status'] = trim($_REQUEST['ai_status']) ;
	$detail_list[0]['type'] = trim($_REQUEST['ai_type']) ;
	$detail_list[0]['api_key'] = trim($_REQUEST['ai_api_key']) ;
	$detail_list[0]['dir_code'] = trim($_REQUEST['ai_dir_code']) ;
	
	$insert_array['table']=$table_Prefix."wechat_official";
		
	$insert_array['items']=array("name","appid","appsecret","public_id","account","status","type","api_key","dir_code");
	$insert_array['values']=$detail_list;
	
	$sql = insert_datas($insert_array);
	
	$res = do_query($sql);

	if($res){
		echo '<script type="text/javascript">alert("新增成功");window.location.href="detail-list.php?nav-itemed=wechat";</script>';
	}
	exit;
}
elseif($act == 'delete'){
	
	$detail = select_one_line_all_items($table_Prefix.'wechat_official', "nid = '$id' ");

	if($detail){
		$sql = 'DELETE FROM '.$table_Prefix.'wechat_official'.' WHERE nid ='.$id;
		
		$res = do_query($sql);
		
		if($res){
			echo '<script type="text/javascript">alert("删除成功");window.location.href="detail-list.php?nav-itemed=wechat";</script>';
			exit;
		}
		else{
			echo '<script type="text/javascript">alert("删除失败");window.location.href="detail-list.php?nav-itemed=wechat";</script>';
			exit;
		}
	}
	else{
		echo '<script type="text/javascript">alert("删除成功");window.location.href="detail-list.php?nav-itemed=wechat";</script>';
			
		exit;
	}
	
}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <?php include ROOT_PATH_.'/controller/common/module/head.php'; ?>
    <?php include 'modules/head.php'; ?>

</head>

<body>

<div id="topbar">   <?php include ROOT_PATH_.'/controller/common/module/topbar.php'; ?></div>

<div id="container" class="<? echo $system_part ?>">

    <div id="maincontent">

        <div id="sidebar">
            <?php include ROOT_PATH_.'/controller/common/module/sidebar.php'; ?>
        </div>


		<div id="content" class="layui-form">
			<h1> 公众号信息 </h1>

			<div class="tips">
				
			</div>
			<div class="detail-box member-edit-box layui-form">

                <div class="detail-boxes">
					<div class="detail-boxing">

					<form id="edit-member-form" method="post" action="detail_info.php?act=<?php echo $next_act;?>" class="layui-form">
 						  <input type="hidden" name="ai_nid" value="<? echo $detail['nid']?>">
                          <div class="layui-form-item">
                            <label class="layui-form-label">公众号名字</label>
                            <div class="layui-input-block">
                              <input type="text" name="ai_name" required  lay-verify="required" placeholder="请输入公众号名字" autocomplete="off" class="layui-input" value="<? echo $detail['name']?>">
                            </div>
                          </div>
                          <div class="layui-form-item">
                            <label class="layui-form-label">公众号appid</label>
                            <div class="layui-input-block">
                              <input type="text" name="ai_appid" required  lay-verify="required" placeholder="请输入公众号appid" autocomplete="off" class="layui-input" value="<? echo $detail['appid']?>">
                            </div>
                          </div>
                          <div class="layui-form-item">
                            <label class="layui-form-label">公众号appsecret</label>
                            <div class="layui-input-block">
                              <input type="text" name="ai_appsecret"  placeholder="请输入公众号appsecret" autocomplete="off" class="layui-input" value="<? echo $detail['appsecret']?>">
                            </div>
                          </div>
                          <div class="layui-form-item">
                            <label class="layui-form-label">公众号public_id</label>
                            <div class="layui-input-block">
                              <input type="text" name="ai_public_id" required  lay-verify="required" placeholder="请输入公众号public_id" autocomplete="off" class="layui-input" value="<? echo $detail['public_id']?>">
                            </div>
                          </div>
                          <div class="layui-form-item">
                            <label class="layui-form-label">公众号account</label>
                            <div class="layui-input-block">
                              <input type="text" name="ai_account" required  lay-verify="required" placeholder="请输入公众号account" autocomplete="off" class="layui-input" value="<? echo $detail['account']?>">
                            </div>
                          </div>
                          <div class="layui-form-item">
                            <label class="layui-form-label">公众号状态</label>
                            <div class="layui-input-block">
                               <select name="ai_status" lay-verify="required">
                                 <option value="">请选择公众号状态</option>
                                 <option value="停用" <?php if($detail['status'] == '停用'){echo 'selected="selected"';}?>>停用</option>
                                 <option value="在用" <?php if($detail['status'] == '在用'){echo 'selected="selected"';}?>>在用</option>
                               </select>
                              
                            </div>
                          </div>
                          <div class="layui-form-item">
                            <label class="layui-form-label">公众号类型</label>
                            <div class="layui-input-block">
                               <select name="ai_type" lay-verify="required">
                                 <option value="">公众号类型</option>
                                 <option value="订阅号" <?php if($detail['type'] == '订阅号'){echo 'selected="selected"';}?> >订阅号</option>
                                 <option value="服务号" <?php if($detail['type'] == '服务号'){echo 'selected="selected"';}?>>服务号</option>
                               </select>
                             
                            </div>
                          </div>
                          <div class="layui-form-item">
                            <label class="layui-form-label">公众号api_key</label>
                            <div class="layui-input-block">
                              <input type="text" name="ai_api_key"    placeholder="请输入公众号api_key （服务号 微信支付API）" autocomplete="off" class="layui-input" value="<? echo $detail['api_key']?>">
                            </div>
                          </div>
                          <div class="layui-form-item">
                            <label class="layui-form-label">公众号所属文件夹</label>
                            <div class="layui-input-block">
                              <input type="text" name="ai_dir_code"    placeholder="请输入公众号所属文件夹路径" autocomplete="off" class="layui-input" value="<? echo $detail['dir_code']?>">
                            </div>
                          </div>

                          <div class="layui-form-item">
                            <div class="layui-input-block">
                              <button class="layui-btn" lay-submit lay-filter="formMemberAdd" type="submit">立即提交</button>
                              <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                          </div>

					</form>
					</div>
				</div>
			</div>

<!--content端點01-->
</div>
<!--maincontent端點01-->
<br class="clearfloat"/>
</div>
<!--container端點01-->
</div>


<?php include ROOT_PATH_ . "/controller/common/module/footer.php"; ?> </body>
</html>
